package api

import (
	"github.com/gin-gonic/gin"
	"learn/consts"
	"learn/forms"
	util "learn/pkg/utils/log"
	"learn/service"
	"strconv"
	_ "strconv"
)

func SavePmsBrand(ctx *gin.Context) {
	pmsBrandForm := forms.PmsBrandForm{}
	if err := ctx.ShouldBind(&pmsBrandForm); err == nil {
		pmsBrandService := service.NewPmsBrandService()
		res := pmsBrandService.Create(&pmsBrandForm)
		ctx.JSON(consts.StatusOK, res)
	} else {
		util.LogrusObj.Error("api/pms_brand error: %v", err)
		ctx.JSON(consts.IlleageRequest, ErrorResponse(err))
	}
}

func PagePmsBrand(ctx *gin.Context) {
	keywords := ctx.DefaultQuery("key", "")
	showStatus, _ := strconv.Atoi(ctx.DefaultQuery("showStatus", "0"))
	pageNum, _ := strconv.Atoi(ctx.DefaultQuery("pageNum", "0"))
	pageSize, _ := strconv.Atoi(ctx.DefaultQuery("pageSize", "0"))
	pmsBrandService := service.NewPmsBrandService()
	res := pmsBrandService.PageList(keywords, showStatus, pageNum, pageSize)
	ctx.JSON(consts.StatusOK, res)
}
